package com.dongwu.manager.service.impl;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dongwu.common.service.impl.BaseServiceImpl;
import com.dongwu.common.utils.UserUtils;
import com.dongwu.manager.dao.MediaDao;
import com.dongwu.manager.entity.Media;
import com.dongwu.manager.service.MediaService;
import com.dongwu.security.service.IUserService;

@Service
public class MediaServiceImpl extends BaseServiceImpl<Media, String> implements MediaService {
	
	@Autowired
	private MediaDao mediaDao;
	@Autowired
	private IUserService userService;
	@Override
	public List<Media> findMedia(String device_id, Integer titleType,Integer pageNo,Integer pageSize) {
		// TODO Auto-generated method stub
		return mediaDao.findMedia(device_id, titleType,pageNo,pageSize);
	}
	@Override
	public Media save(Media entity) {
		/*如果背景为颜色时去掉开头的,号*/
		if(entity.getBackgroundContent().startsWith(",")){
			entity.setBackgroundContent(entity.getBackgroundContent().substring(1, entity.getBackgroundContent().length()));
		}
		/*关联当前用户*/
		if (entity.getUser() == null) {
			entity.setUser(userService.findByLoginName(UserUtils.getUserLoginName()));
		}
		return super.save(entity);
	}
	@Override
	public List<Media> findMedia(String device_id, Integer titleType) {
		// TODO Auto-generated method stub
		return mediaDao.findMedia(device_id, titleType);
	}
}
